<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Trang chủ</title>
<link rel="shortcut icon" href="../Images/Icons/SunstormLogo.gif" />
<link rel="stylesheet" href="../CSS/css_webnews.css"/>
<link href="../Menu_Zing/SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<link href="../CSS/wt-rotator.css" rel="stylesheet" type="text/css" />
<link href="../CSS/slider.css" rel="stylesheet" type="text/css" />
<link href="../weather/weather.css" rel="stylesheet" type="text/css" />
<link href="../CSS/black-tie/jquery-ui-1.8.20.custom.css" rel="stylesheet" type="text/css" />
<link href="../CSS/experiment.css" rel="stylesheet" type="text/css" />
 

<script src="../Menu_Zing/SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<script src="../Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="../Scripts/preview.js" type="text/javascript"></script>
<script src="../Scripts/jquery.wt-rotator.min.js" type="text/javascript"></script>
<script type="text/javascript" src="../Scripts/jquery-ui-1.8.20.custom.js" ></script>
<script language="javascript" src="../weather/js/ajax.js"></script>
<script language="javascript" src="../Scripts/floater_xlib.js"></script>
<script language="javascript" src="../Scripts/Advertise_twoside.js"></script>
<script language="javascript" src="../Scripts/boxover.js"></script>
<script language="javascript" src="../Scripts/jquery.jqDock.min.js"></script>


<style> 

     </style> 
</head>

<body>
<?php 
include("../Connections/connect_client.php");
require_once("include/Advertise_twoside.php");
function getSubMenu($parent)
{
	$submenu='';
	$res=mysql_query("SELECT t.TopicID FROM topic t WHERE t.IsDeleted=0 and t.ParentID=$parent");
	while($t=mysql_fetch_assoc($res))
	{
		$submenu.='<'.$t["TopicID"].'>';
		$submenu.=getSubMenu(intval($t["TopicID"]));
	}
	return $submenu;
}
$keyword="";
$fromdate="";
$todate="";
$topic=0;
$type=-1;
$order="DESC";
$orderby="Views";
$link="";
	if(isset($_GET['keyword']))
	{
		$keyword=$_GET['keyword'];
		$link.="keyword=$keyword&";
	}
	if(isset($_GET['fromdate']))
	{
		$fromdate=$_GET['fromdate'];
		$link.="fromdate=$fromdate&";
	}
	if(isset($_GET['todate']))
	{
		$todate=$_GET['todate'];
		$link.="todate=$todate&";
	}
	if(isset($_GET['topic']))
	{
		$topic=$_GET['topic'];
		$link.="topic=$topic&";
	}
	if(isset($_GET['type']))
	{
		$type=$_GET['type'];
		$link.="type=$type&";
	}
	if(isset($_GET['order']))
	{
		$order=$_GET['order'];
		$link.="order=$order&";
	}
	if(isset($_GET['orderby']))
	{
		$orderby=$_GET['orderby'];	
		$link.="orderby=$orderby&";
	}
?>
<div id="main">
  <div class="header"></div>
  <div class="menu"><?php
  $urlAds="../Images/Advertisement/";
  $urlNews="../Images/Img_News/";
  $urlIcon="../Images/Icons/";
  require("../Menu_Zing/Zing/MenuNgang.php"); 
  require("include/JdockMenu.php");
  require("include/Feedback_modal.php");
  ?></div>
   <!----------------------------------------Bar Search + BreadCrumb------------------------------------------------------>
  <div class="searchBar" >
   <form action="" method="get" id="frmQuicksearch">
    <div class="searchBox" >
        	<input type="text" placeholder="Tìm kiếm..." name="keyword"  />
            <input type="image" src="../Images/Icons/Knob Search.ico" onclick="this.submit();"   />       
    </div>
  	</form>
  </div>
  <!----------------------------------------Content------------------------------------------------------>
  <div class="left">
  
  <!----------------------------------------------Search ----------------------------------------------------->
  	
  	<div style="background-color:#FFF; padding:3px">
    	<div class="divTitle"><span class="titlePage" >Tìm kiếm</span></div>
         <form action="" method="get" >
		 <table width="100%" border="0" cellspacing="5" cellpadding="0" style="border-bottom:solid 1px #08c">
         
          <tr>
            <td>Từ khóa:</td>
            <td colspan="3"><input type="text" name="keyword" id="keyword" value="<?php echo $keyword; ?>" style="width:40%" /></td>
            
          </tr>
          <tr>
            <td>Từ ngày:</td>
            <td><input type="text" name="fromdate" id="fromdate" value="<?php echo $fromdate; ?>" /></td>
            <td>Đến ngày:</td>
            <td><input type="text" name="todate" id="todate" value="<?php echo $todate; ?>" /></td>
            <script>
				$(function() {
					$( "#fromdate,#todate" ).datepicker({
						showOn: "button",
						buttonImage: "../Images/Icons/calendar_date.png",
						buttonImageOnly: true,
						dateFormat:'dd-mm-yy'
					});
				});
			</script>
          </tr>
          <tr>
            <td>Chuyên mục:</td>
            <td>
            	<select name="topic" id="cbxTopic">
                <option value="0">---Tất cả chuyên mục---</option>
					 <?php	  
                    function Menu2($cap = 0,$gach = '&gt;&gt;  ', $arr = NULL){  
                    if(!$arr) $arr = array();//khoi tao 1 array co ten la arr  
                    $sql = mysql_query("SELECT * FROM topic WHERE IsDeleted = 0 and IsAllowWriteNews=1 and ParentID = ".$cap." order by OrderIndex");  
                    while($row = mysql_fetch_assoc($sql)){  
                    $arr[] = array('id'=>$row['TopicID'],'ten'=>$gach.$row['TopicName']);  
                    $arr = Menu2($row['TopicID'],$gach.'&gt;&gt;   ',$arr);  
                    }  
                    return $arr;  
                    }  
                    $Menu = Menu2(0);  
            
                     foreach($Menu as $k=>$row)
                     {
                     ?>
                     <option value="<?php echo $row["id"]; ?>" <?php if($topic==$row["id"]) echo 'selected="selected"'; ?>><?php echo $row["ten"]; ?></option>
                    <?php
                     }
                    ?>       	
                </select>
            </td>
            <td>Loại bài:</td>
            <td>
            	<select name="type" id="cbxType" style="max-width:120px">
                    <option value="-1" <?php if($type==-1) echo 'selected="selected"'; ?>>---Tất cả---</option>
                    <option value="0"  <?php if($type==0) echo 'selected="selected"'; ?>>Bình thường</option>
                    <option value="1"  <?php if($type==1) echo 'selected="selected"'; ?>>Hình ảnh</option>
                    <option value="2"  <?php if($type==2) echo 'selected="selected"'; ?>>Video</option>
                </select>
            </td>
          </tr>
          <tr>
            <td>Sắp xếp:</td>
            <td>
            	<select name="order" id="cbxOrder" style="max-width:120px">
                    <option value="ASC" <?php if($order=='ASC') echo 'selected="selected"'; ?>>Tăng dần</option>
                    <option value="DESC"  <?php if($order=='DESC') echo 'selected="selected"'; ?>>Giảm dần</option>
                   
                </select>
            </td>
            <td>Theo:</td>
            <td>
            	<select name="orderby" id="cbxOrderBy" style="max-width:120px">
                    <option value="Views" <?php if($orderby=="Views") echo 'selected="selected"'; ?>>Số lượt xem</option>
                    <option value="Rating"  <?php if($orderby=="Rating") echo 'selected="selected"'; ?>>Điểm đánh giá </option>
                    
                </select>
            </td>
          </tr>
          <tr>
            <td colspan="4" style="text-align:center">
            <input type="submit" value="Tìm kiếm" id="btnSearching" style=" width:100px; height:30px; font-weight:bold" />
            </td>
          </tr>
        </table>
 		</form>
	</div>
  <!----------------------------------------------End Seach----------------------------------------------------->
  <!----------------------------------------------Results----------------------------------------------------->
  <div id="content">
  <!--Tin 1--->
 		<div class="div_topic">
    
    <?php
		$page=1;
		$recordPerPage=10;
		if(isset($_GET["page"]))
			{
				$page=intval($_GET["page"]);
			}
		$index=($page-1)*$recordPerPage;
		$sqlAll="SELECT n.NewsID, n.NewsType, n.TopicID, n.Title, n.Description, n.Image, n.IsHot,n.CreatedDate,n.Views,n.Rating FROM news n WHERE n.IsDeleted=0 AND n.IsReview=1 ";
		if($keyword!="")
			$sqlAll.="AND (n.Title LIKE '%$keyword%' OR n.Description LIKE '%$keyword%') ";
		if($fromdate!='')
		{
			$arr1=explode('-',$fromdate);
			$fromdate=$arr1[2].'-'.$arr1[1].'-'.$arr1[0];
			
			$sqlAll.="AND n.CreatedDate >='$fromdate' ";
		}
		if($todate!='')
		{
			$arr2=explode('-',$todate);
			$todate=$arr2[2].'-'.$arr2[1].'-'.$arr2[0];
			
			$sqlAll.="AND n.CreatedDate <='$todate' ";
		}
		$listTopic='<'.$topic.'>'.getSubMenu($topic);
		$sqlAll.="AND '$listTopic' LIKE CONCAT('%<',n.TopicID,'>%') ";
		$sqlAll.="AND (n.NewsType=$type OR $type=-1) ";
		$sqlAll.="ORDER BY $orderby $order ";
		$sqlnews=$sqlAll."LIMIT $index,$recordPerPage ";
		$resnews=mysql_query($sqlnews);
		while($fnews=mysql_fetch_assoc($resnews))
		{
	?>
    <div class="tp_content">
    	<div class="top_news" style="width:100%">
        	<a href="Detail.php?id=<?php echo $fnews["NewsID"]; ?>" title="">
            	<img src="<?php echo $urlNews.$fnews["Image"]; ?>" alt="" style="width:150px; margin:8px" />
            </a>
            <div style="float:left; width:490px;margin-top: 5px;">
            	<a href="Detail.php?id=<?php echo $fnews["NewsID"]; ?>" title="">
                <?php 
					echo $fnews["Title"];
					if($fnews["NewsType"]==1)
						echo "<img src='".$urlIcon."photo.gif' alt='' />";
					else if($fnews["NewsType"]==2)
						echo "<img src='".$urlIcon."video.gif' alt='' />";
					if($fnews["IsHot"]==1)
						echo "<img src='".$urlIcon."hot.gif' alt='' />";
				?> 
                </a>
                <br />
                <p><i>Số lượt xem: <?php echo $fnews["Views"]; ?> lượt</i><br /><?php echo $fnews["Description"]; ?></p>
            </div>
        </div>
         <div style="clear:both"></div>
    </div>
        <?php
		}
		?>
       <div class="pagination pull-right">
  		<?php
			$link2="SearchNews.php?".$link;		
			$resAll=mysql_query($sqlAll);
			$total=mysql_num_rows($resAll);
			//echo $link;
              require("../Admin/process/funcPaging.php");
			Paging($total,$page,5,$recordPerPage,$link2);
 		?>  
    </div>
  </div>
  

  
  <!----End--->
  </div>
<!----------------------------------------------End Results----------------------------------------------------->
  </div>
  <div class="right">
  <!----------------------------------------------Weather+Stock----------------------------------------------------->
  	<div id="weather">
    <?php include("../weather/index.php"); ?>
    </div>
   <div id="stock">
    <?php include("include/stock.html"); ?>
    </div> 
   <!----------------------------------------Hot News----------------------------------------->
     <div id="hotnews">
     	<div class="title"></div>
        <div class="hot">
       	  <ul>
          <?php
		  $hotsql="SELECT n.NewsID, n.Title, n.Image FROM news n WHERE n.IsDeleted=0 AND n.IsReview=1 ORDER BY n.Views DESC LIMIT 0,5 ";
		  $reshot=mysql_query($hotsql);
		  while($hot=mysql_fetch_assoc($reshot))
		  {
		  ?>
            	<li> 
                	<img src="<?php echo $urlNews.$hot["Image"]; ?>" alt="" style="width:80px; height:50px" />
                    <a href="Detail.php?id=<?php echo $hot["NewsID"]; ?>"><?php echo $hot["Title"]; ?></a>
                </li>
          <?php
		  }
		  ?>
               
            </ul>
       </div>
    </div>
    <!-----------------------------------Vote---------------------------------------------->
    <div id="vote">
    	<div class="title"></div>
        <div class="hot">
        <form method="get" action="captcha/confirm.php" target="_blank">
        <?php
			$votesql="SELECT v.VoteID, v.VoteName, v.Content FROM vote v WHERE v.IsDeleted=0 AND v.IsEnd=0 ORDER BY v.CreatedDate desc LIMIT 0,1"; 
			$resvote=mysql_query($votesql);
			$vote=mysql_fetch_assoc($resvote);
			echo $vote["Content"];
			
		?>
            <ul>
            <?php
			$vdsql="SELECT v.VoteDetailID, v.Content FROM votedetail v WHERE v.VoteID=".intval($vote["VoteID"])." ORDER BY v.VoteDetailID";
			$resvd=mysql_query($vdsql);
			$k=0;
			while($dt=mysql_fetch_assoc($resvd))
			{
			?>
            	<li><label><input type="radio" name="answer" <?php if($k==0) echo "checked='checked'"; ?> value="<?php echo $dt["VoteDetailID"]; ?>"  /><?php echo $dt["Content"]; ?></label></li>
            <?php
			$k++;
			}
			?>
                <!--<li><label><input type="radio" name="answer" id="cauB" value="" />Đức</label></li>
                <li><label><input type="radio" name="answer" id="cauC" value="" />Pháp</label></li>
                <li><label><input type="radio" name="answer" id="cauD" value="" />Đội bóng khác</label></li> -->
            </ul>
           <?php
			if(mysql_num_rows($resvote)>0)
			{
			?>
            <a id="bieuquyet" target="_blank" href="include/StatisticResult.php?voteid=<?php echo $vote["VoteID"];  ?>">Thống kê</a>&nbsp;&nbsp;<input type="submit" value="Biểu quyết" />
            <?php
			}
			?>
          </form>
       </div>
    </div>
    
    <!-------------------------------------Advertisement-------------------------------------------->
    <div id="advertisement_right">
    	<div class="title"></div>
        <div class="hot">
       	  	
            <ul>
            <?php 
			$query="SELECT a.AdvertiseName, a.FileType, a.FilePath, a.Link FROM advertisement a WHERE a.`Position`=4 AND a.IsDeleted=0 ORDER BY a.CreatedDate desc limit 0,5";
			
			$adver=mysql_query($query);
			while($row=mysql_fetch_assoc($adver))
			{
			
			switch($row['FileType'])
			{
				case 0:
				?>
				 <li><a href="<?php echo $row['Link']; ?>"><img alt="" src="<?php echo $urlAds.$row['FilePath']; ?>"   /></a></li>
				<?php
				break;
				case 1:
				?>
					<object width="250"  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
			<param value="quangcao/qc1.swf" name="movie">
			<param value="high" name="quality">
			<embed width="250"  type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" quality="high" src="<?php echo $urlAds.$row['FilePath']; ?>">
			</object>
				<?php
				break;
			}
		
			}
			?>
              
          </ul>
           
       </div>
    </div>
  </div>

  
  
  <!------------------------------Footer--------------------------------------------------->
  <div class="footer">
  	<p>
    	Designed by: Nguyen Minh Nhat<br />
        Email: mimhnhat2110@gmail.com<br />
        Mobile: 0908311627
    </p>
  </div>
</div>

 
</body>
</html>